package com.test.liuhb.test;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;

/**
 * Created by liu.hb on 2017/10/30.
 */

public class ImageActivity extends Activity {
    ImageSwitcher imageSwitcher;
    private boolean showImg1=true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageswitcher);
        imageSwitcher=(ImageSwitcher)findViewById(R.id.imageSwitcher);
        imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new ImageView(ImageActivity.this);
            }
        });
        imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(ImageActivity.this, android.R.anim.fade_in));
        imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(ImageActivity.this, android.R.anim.fade_out));
        imageSwitcher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showImg1=!showImg1;
                showCurrentImage();
            }
        });
        showCurrentImage();
    }



    private void showCurrentImage(){
        System.out.println(showImg1);
        System.out.println(imageSwitcher);
        if(showImg1){
            imageSwitcher.setImageResource(R.drawable.storage);
        }else{
            imageSwitcher.setImageResource(R.drawable.download);
        }
    }
}
